import http from '../http.js';
var market_cart = {}

market_cart.getIndex = function( cb ){
  http.doGet("/index" , {} , function( response ){
    if(response.data.status ==1){
      cb(response.data);
    }else{
      wx.showToast({
        title: response.data.message
      })
    }
  })

}

market_cart.getMarketSetting = function( params , cb ){
  http.doGet("/market/getMarketSetting" , params , function(response){
    cb(response.data)
  })

}
/**
 * 添加商品购物车
 * @param {*} params 
 * @param {*} cb 
 */
market_cart.addProductToCart = function(  params , cb){
    http.doGet("/marketCart/addGood" , params , function( response ){
        if(response.data.status ==1){
          cb(response.data);
        }else{
          wx.showToast({
            title: response.data.message
          })
        }
      })
}

market_cart.reduceProductToCart = function( params , cb ){

  http.doGet("/marketCart/reduceGood" , params , function( response ){
    if(response.data.status ==1){
      cb(response.data);
    }else{
      wx.showToast({
        title: response.data.message
      })
    }
  })

}
/**
 * 清空购物车
 * @param {*} params 
 * @param {*} cb 
 */
market_cart.clearCartGoods = function( params , cb ){
    http.doGet("/marketCart/clearCartGoods" , params , function( response ){
        cb(response.data)
    })
}
/**
 * 加载购物车商品列表
 * @param {*} params 
 * @param {*} cb 
 */
market_cart.getCartGoodList = function( params  ,cb ){
  http.doGet("/marketCart/getCartGoodList" ,params ,  function(response){
    cb(response.data)
  })
}

/**
 * 加载支持配送区域
 */
market_cart.getMarketAddressList = function( params , cb ){
  http.doGet("/market/getMarketAddressList" , params , function( response ){
    cb(response.data)
  })

}

/**
 * 添加个人发货地址设置信息
 */

 market_cart.addMarketUserAddress = function( data , cb ){
   http.doPost("/market/addMarketUserAddress" , data , function( response ){
     cb(response.data)
   })
 }
 /**
  * 加载用户地址列表
  * @param {*} params 
  * @param {*} cb 
  */

 market_cart.getUserMarketAddressList = function(params , cb){
   http.doPost("/marketAddress/getUserMarketAddressList" , params , function(response){
     cb(response.data);
   })
 }
/**
 * 删除用户地址
 * @param {}} params 
 * @param {*} cb 
 */
 market_cart.deleteUserAddress = function( params ,cb ){
   http.doGet("/marketAddress/deleteUserAddress" , params, function(response){
     cb(response.data)
   })
 }

 //创建订单
 market_cart.createMarketOrder = function( data , cb ){
   http.doPost("/marketOrder/createMarketOrder" , data , function(response){
     cb(response.data)

   })
 }

 market_cart.preOrder = function( params , cb){
   http.doGet("/marketOrder/preOrder" , params, function(response){
     cb(response.data)
   })
 }
//加载收货地址详情
 market_cart.getUserAddressById = function( params , cb ){
   http.doGet("/marketAddress/getUserAddressById" , params , function(response){
     cb(response.data)
   })

 }
//更新收货地址
 market_cart.updateUserAddress  = function( data , cb ){
   http.doPost("/marketAddress/updateUserAddress" , data, function(response){
     cb(response.data)
   })
 }

 market_cart.doMarkerOrderPay = function( params , cb ){
  http.doGet("/marketOrder/doMarketOrderPay" , params, function(response){
    cb(response.data)
  })

 }

 market_cart.getCompanyInfo = function(params , cb){
   http.doGet("/setting/getCompanyInfo" , params , function( response){
      cb(response.data)
   })
 }

 market_cart.getCoupouList = function(params , cb){
   http.doGet("/coupou/getCoupouList" ,  params ,  function(response){
     cb(response.data)

   })
 }

export default market_cart;